<template>
  <el-dialog
    title='法律法规'
    :visible.sync="dialogVisible"
    @opened="dialogOpen"
  >
    <el-form
      ref="form"
      :model="form"
      label-width="80px"
      size="small"
    >
      <el-form-item
        prop="strName"
        label="法规名称"
      >
        <el-input v-model="form.strName" disabled="disabled"></el-input>
      </el-form-item>
      <el-form-item
        prop="code"
        label="法条编码"
      >
        <el-input v-model="form.code"></el-input>
      </el-form-item>
      <el-form-item
        prop="item"
        label="条"
      >
        <el-input v-model="form.item"></el-input>
      </el-form-item>
      <el-form-item
        prop="yjtl"
        label="违反条例"
      >
        <el-input v-model="form.yjtl"></el-input>
      </el-form-item>
      <el-form-item
        prop="upperLimit"
        label="罚款上限"
      >
        <el-input v-model="form.upperLimit"></el-input>
      </el-form-item>
      <el-form-item
        prop="lawerLimit"
        label="罚款下限"
      >
        <el-input v-model="form.lawerLimit"></el-input>
      </el-form-item>
      <el-form-item
        prop="cfbz"
        label="处罚标准"
      >
        <el-input type="textarea" v-model="form.cfbz" style="height: 100px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :loading="loading"
          @click="saveUser"
        >保存
        </el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>

  </el-dialog>

</template>
<script>
  import itemsApi from "@/api/system/caseCauselawcontent";

  export default {
    name: "bnslawEditForm",
    props: {
      dept: Object,
      value: Boolean
    },
    data() {
      return {
        loading: false,
        dialogVisible: false,
        form: {
          code: "",
          strName: '',
          item: '',
          yjtl: '',
          upperLimit: '',
          lawerLimit: '',
          cfbz: '',
          lawContentId: ''
        },
        publics: [],
      };
    },
    watch: {
      value(val) {
        this.dialogVisible = val;
      },
      dialogVisible(val) {
        this.$emit("input", val);
      }
    },
    methods: {
      dialogOpen() {
        this.$refs.form.resetFields();
        this.form = this.dept;
        /* if (this.dept.id) {
          itemsApi.Page({lawContentId:this.dept.lawContentId}).then(res => {
            var temp = res.data.rows
            let form = {};
            temp.forEach(element => {
              if(this.dept.id == element.id){
                form.code = element.code;
                form.strName = element.strName;
                form.item = element.item;
                form.yjtl = element.yjtl;
                form.upperLimit = element.upperLimit;
                form.lawerLimit = element.lawerLimit;
                form.cfbz = element.cfbz;
                form.lawContentId = element.lawContentId;
                this.form = form;
              }
            });
          });
        } else {
          this.form = {};
        } */
      },

      saveUser() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.loading = true;
            console.log(this.form);
            itemsApi
              .mod({...this.form, id: this.dept.id})
              .then(data => {
                this.loading = false;
                this.dialogVisible = false;
                this.$emit("submit");
              });

          } else {
            return false;
          }
        });
      },
      close() {
        this.$refs["form"].resetFields();
        this.dialogVisible = false;
      }
    }
  };
</script>

